<template>
  <div id="loadmem">
    <div class="panel panel-primary">
      <!-- Default panel contents -->
      <!--<div class="panel-heading">初始化共享内存</div>-->
      <el-alert style="margin-top:10px;" title="初始化共享内存" type="info" :closable="false">
      </el-alert>

      <el-row :span="4" :xs="8" :sm="6" :md="4">
        <el-col :span="4" :xs="8" :sm="6" :md="4">
          <div class="grid-content bg-purple" style="text-align: center;margin-top:20px" @click="initShareMem('all','全部缓存')">
            <a class="thumbnail">
              <img src="../../../static/img/all.png">
              <div class="caption" style="text-align: center;">
                全部缓存
              </div>
            </a>
          </div>
        </el-col>



        <el-col :span="4" :xs="8" :sm="6" :md="4">
          <div class="grid-content bg-purple" style="text-align: center;margin-top:20px" @click="initShareMem('code','公共代码')">
            <a class="thumbnail">
              <img src="../../../static/img/sys.code.png">
              <div class="caption" style="text-align: center;">
                公共代码
              </div>
            </a>
          </div>
        </el-col>

        <el-col :span="4" :xs="8" :sm="6" :md="4">
          <div class="grid-content bg-purple" style="text-align: center;margin-top:20px" @click="initShareMem('svrinf','三方地址')">
            <a class="thumbnail">
              <img src="../../../static/img/svr-info.png">
              <div class="caption" style="text-align: center;">
                三方地址
              </div>
            </a>
          </div>
        </el-col>


        <el-col :span="4" :xs="8" :sm="6" :md="4">
          <div class="grid-content bg-purple" style="text-align: center;margin-top:20px" @click="initShareMem('menu','菜单信息')">
            <a class="thumbnail">
              <img src="../../../static/img/sys-menu.png">
              <div class="caption" style="text-align: center;">
                菜单信息
              </div>
            </a>
          </div>
        </el-col>

        <el-col :span="4" :xs="8" :sm="6" :md="4">
          <div class="grid-content bg-purple" style="text-align: center;margin-top:20px" @click="initShareMemss('planInfo','前端缓存')">
            <a class="thumbnail">
              <img src="../../../static/img/agreementconf.png">
              <div class="caption" style="text-align: center;">
                前端缓存
              </div>
            </a>
          </div>
        </el-col>







      </el-row>

      <el-alert style="margin-top:10px;" title="清除缓存" type="info" :closable="false">
      </el-alert>
      <el-row :span="4" :xs="8" :sm="6" :md="4">
        <el-col :span="4" :xs="8" :sm="6" :md="4">
          <div class="grid-content bg-purple" style="text-align: center;margin-top:20px" @click="initShareMems('TOKEN','微信Tkoen')">
            <a class="thumbnail">
              <img src="../../../static/img/kind.png">
              <div class="caption" style="text-align: center;">
                微信全局Token
              </div>
            </a>
          </div>
        </el-col>
      </el-row>

    </div>
  </div>
</template>

<script type="text/javascript">
import { LOADMEN_URL,clearAccessToken,refresh } from '../../api/api';
export default {
  data() {
    return {
      author: ""
    }
  }
  , methods: {
    initShareMem: function (_type, desc) {
      this.$confirm('你确定要加载 [ ' + desc + ' ] 共享内存吗？', '共享内存加载', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        if(_type=="all"){
          let para = new FormData();
          para.append('type','planInfo');
          refresh(para).then((res) => {
              if (res.data.state == 0) {
                this.$message({
                  type: 'success',
                  message: '加载缓存成功!'
                });
              }
              else {
                this.$message({
                  type: 'error',
                  message: res.data.result
                });
              }
          });
        }
        this.loadMem(_type);
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消刷新缓存'
        });
      });
    },
    initShareMems: function(){
       this.$confirm('你确定要清除微信全局Token', '清除微信全局Token', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        clearAccessToken().then((res) =>{
          if(res.data.success){
            this.$message({
              type: 'success',
              message: '清除成功'
            });
          }
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消清除微信全局Token'
        });
      });
    },

    initShareMemss: function(_type, desc){
       this.$confirm('你确定要加载 [ ' + desc + ' ] 共享内存吗？', '共享内存加载', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
          let para = new FormData();
          para.append('type',_type);
          refresh(para).then((res) => {
              if (res.data.state == 0) {
                this.$message({
                  type: 'success',
                  message: '加载缓存成功!'
                });
              }
              else {
                this.$message({
                  type: 'error',
                  message: res.data.result
                });
              }
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消刷新缓存'
        });
      });
    },
    /**
     * [loadMem description]
     * @param  {[type]} _type [description]
     * @return {[type]}       [description]
     */
    loadMem: function (_type) {
      let data = { "type": _type };
      let _this = this;
      // $.ajax({
      //   type: "POST",
      //   url: LOADMEN_URL,
      //   data: data,
      //   success: function (data, status, xhr) {
      //     // 这里是处理正确的回调
      //     if (data.state == 0) {
      //       _this.$message({
      //         type: 'success',
      //         message: '加载缓存成功!'
      //       });
      //     } else {
      //       _this.$message({
      //         type: 'error',
      //         message: data.result
      //       });

      //     }
      //   }
      // });
      let para = new FormData();
      para.append('type',_type);
      LOADMEN_URL(para).then((res) => {
          if (res.data.state == 0) {
            _this.$message({
              type: 'success',
              message: '加载缓存成功!'
            });
          }
          else {
            _this.$message({
              type: 'error',
              message: res.data.result
            });
          }
    });

  }



}


}

</script>

<style>
.bg-purple {
  border: 1px solid #ddd;
  border-radius: 4px;
  padding-top: 10px;
  padding-bottom: 10px;
}

a {
  text-decoration: none;
  color: black;
}

.thumbnail a>img,
.thumbnail>img {
  height: 40px;
}
</style>